<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 引入vue -->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <!-- 引入axios -->
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!-- 配置axios的基础路径和全局属性 -->
    <script src="js/common.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/javascript">
    new Vue({
        el: "#app",
        mounted() {
            let url = location.href;
            let code = param2JsonObj(url).code;
            this.$http.get("/login/wechat/"+code).then(res => {
                if (res.data.success) { // 登录成功
                    // 提示
                    alert("登陆成功！！！");
                    // 保存token和logininfo对象到localStorage
                    let token = res.data.resultObj.token;
                    let logininfo = res.data.resultObj.logininfo;
                    localStorage.setItem("token",token);
                    // localStorage保存的数据是字符串，所以要将json对象转成json格式的字符串
                    localStorage.setItem("logininfo",JSON.stringify(logininfo));
                    location.href = "/index.html";
                } else { // 没有绑定
                    // 跳转到绑定页面
                    let access_token = res.data.resultObj.access_token;
                    let openid = res.data.resultObj.openid;
                    location.href = "/binder.html?accessToken="+access_token+"&openId="+openid;
                }
            }).catch (res => {
                alert("系统繁忙，请稍后重试！！！")
            })
        }
    })
</script>
</body>
</html>